package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CustomerPlan;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerPlanMapper;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.CustomerPlanQueryObject;
import cn.wolfcode.crm.service.ICustomerPlanService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerPlanServiceImpl implements ICustomerPlanService{

    @Autowired
    private CustomerPlanMapper customerPlanMapper;

    public List<CustomerPlan> selectAll() {
        return customerPlanMapper.selectAll();
    }


    public PageResult query(CustomerPlanQueryObject qo) {

        int totalCount = customerPlanMapper.queryForCount(qo);
        if(totalCount == 0){
            return new PageResult();
        }
        List<CustomerPlan> list = customerPlanMapper.queryForList(qo);
        return new PageResult(totalCount,list);
    }

    public void updateByPrimaryKey(CustomerPlan customerPlan) {
        customerPlanMapper.updateByPrimaryKey(customerPlan);
    }

    public void deletePlan(Long id) {
        customerPlanMapper.deleteByPrimaryKey(id);
    }

    public void insert(CustomerPlan customerPlan) {
        Employee inputUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        customerPlan.setInputUser(inputUser);
        customerPlanMapper.insert(customerPlan);
    }

    public void remark(Long id, Integer result) {
        customerPlanMapper.updateResultById(id,result);
    }

}
